
var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://localhost:27017/zhihuishequ';

var insertData = function(db, callback) {
    var dbo = db.db("zhihuishequ");
    dbo.createCollection('users');
    var collection = dbo.collection("users");
    var data = [{"name":'admin',"password":"admin"},{"name":'test',"password":"test"}];
    collection.insert(data, function(err, result) {
        if(err)
        {
            console.log('Error:'+ err);
            return;
        }
        callback(result);
    });
}

MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
    console.log("连接成功！");
    insertData(db, function(result) {
        console.log(result);
        db.close();
    });
});